/*
 *  ifxerror.hpp - exception classes for Informix server and driver errors
 *
 *    Copyright (c) 2001-2006, Luxena Software Company. All rights reserved.
 *
 *  Purpose:
 *
 */

#ifndef __IFXERROR_HPP__
#define __IFXERROR_HPP__

#ifndef __cplusplus
#error This header requires a C++ compiler ...
#endif

#include <exception>
#include <ifxtypes.h>
#include <sqlhdr.h>
#include "cstr.hpp"


/////////////////////////////////////////////////////////////////////////////
// CInformixDriverError - exception class for Informix driver error

class CInformixDriverError : public std::exception
{
public:
	CInformixDriverError (const char *message): _message(message) {}
	virtual const char * what () const throw() { return _message; }
private:
	_cstr_t _message;
};


/////////////////////////////////////////////////////////////////////////////
// CInvalidCastError

class CInvalidCastError : public std::exception
{
public:
	virtual const char *what () const throw() { return "Invalid cast"; }
};


/////////////////////////////////////////////////////////////////////////////
// CInvalidParameterTypeError

class CInvalidParameterTypeError : public std::exception
{
public:
	virtual const char *what () const throw() { return "Allowed parameter type is only INPUT"; }
};


/////////////////////////////////////////////////////////////////////////////
// CInformixServerError - exception class for Informix server error

class CInformixServerError : public std::exception
{
public:
	CInformixServerError (mint sqlCode);
	virtual ~CInformixServerError () {}
	virtual const char * what () const throw() { return _message; }
	mint sqlCode () const { return _sqlCode; }
private:
	_cstr_t _message;
	mint _sqlCode;
};


/////////////////////////////////////////////////////////////////////////////
// Informix API result check functions

inline void checkInformixResult (mint sqlCode)
{
	if (sqlCode < 0)
		throw CInformixServerError(sqlCode);
}

inline void checkInformixResult ()
{
	checkInformixResult(SQLCODE);
}

#endif // __IFXERROR_HPP__
